<?php
namespace jy_xiangqin;
defined('BY_JYA') or exit('error');
/*
*/
class worker extends \plugin{
	
	public function register($data=array()){
		$insert=array(
			'mid'=>$_SESSION['uid'],
			'uniacid'=>$_SESSION['uniacid'],
			'title'=>trim($data['title']),
			'mobile'=>trim($data['mobile']),
			'wechat'=>trim($data['wechat']),
			'fuwuid'=>intval($data['fuwuid']),
			'diyfields'=>$data['diyfields'],
			'status'=>0,
			'createtime'=>TIMESTAMP,
		);
		$this->insert('worker',$insert);
		$pid=$this->pdo_insertid();
		return $pid;
	}
	/*
		会员注册
	*/
	public function checklogin(){
		global $_AR;
		if(!$_SESSION['uid']){
			$_SESSION['forward_url']=$_AR['access_json'];
			model('core/core')->checklogin();
		}else{
			$worker=pdo_get('jy_xiangqin_worker',array('mid'=>$_SESSION['uid'],'uniacid'=>$_SESSION['uniacid']));
			if($worker['status']!=1){
				exi('','','/worker.apply/');
			}
		}
		return $worker;
	}
	public function getlog($params=array()){
		$worker_logid=$params['worker_logid'];
		$worker_id=$params['worker_id'];
		if(!$worker_logid){
			exi('请选择任务！','error');
		}
		$worker_log=pdo_get('jy_xiangqin_worker_log',array('id'=>$worker_logid));
		pdo_update('jy_xiangqin_worker_log',array('worker_id'=>$worker_id),array('id'=>$worker_logid));
		pdo_update('jy_xiangqin_member',array('worker_id'=>$worker_id),array('mid'=>$worker_log['mid']));
		pdo_update('jy_xiangqin_member',array('worker_id'=>$worker_id),array('mid'=>$worker_log['tomid']));
		return true;
	}
	public function yuered($pinglogid,$worker_id=0,$msg=''){
		if(!$pinglogid){
			exi('请选择信息！','error');
		}
		$pinglog=pdo_get('jy_xiangqin_pinglog',array('id'=>$pinglogid));
		if(!$worker_id){
			$worker_id=pdo_getcolumn('jy_xiangqin_member',array('mid'=>$pinglog['mid']),'worker_id');
			if(!$worker_id){
				$worker_id=pdo_getcolumn('jy_xiangqin_member',array('mid'=>$pinglog['tomid']),'worker_id');
			}
		}
		if($worker_id){
			pdo_update('jy_xiangqin_member',array('worker_id'=>$worker_id),array('mid'=>$pinglog['mid']));
			pdo_update('jy_xiangqin_member',array('worker_id'=>$worker_id),array('mid'=>$pinglog['tomid']));
		}
		$msg=$msg?:'客户想进一步了解一下对方！';
		$insert=array(
			'mid'=>$pinglog['mid'],
			'tomid'=>$pinglog['tomid'],
			'uniacid'=>$_SESSION['uniacid'],
			'ordersn'=>'SN'.get_ordersn($this->tablename('worker_log'),'ordersn'),
			'msg'=>$msg,
			'pinglogid'=>$pinglogid,
			'worker_id'=>$worker_id,
			'type'=>0,
			'status'=>0,
			'createtime'=>TIMESTAMP,
		);
		$this->insert('worker_log',$insert);
		return true;
	}
	public function logstatus1($pinglogid){
		$order=pdo_update('jy_xiangqin_worker_log',array('status'=>1),array('id'=>$pinglogid,'uniacid'=>$_SESSION['uniacid']));
		return true;
	}
	public function logstatus2($pinglogid){
		$order=pdo_update('jy_xiangqin_worker_log',array('status'=>2),array('id'=>$pinglogid,'uniacid'=>$_SESSION['uniacid']));
		return true;
	}
}